function [y]=flange(fs, y, variation, rate)
%      fs = Sample rate
%      v = Variation.
%      x = Input audio signal. This should be a column 
%          vector.
%      r = Rate.
v=variation;r=rate;
norms=norm(y);
md= ceil(v*fs);
n=1:length(y)+md;
v=round(v*fs);
z=zeros(md,1);
m=max(abs(y));
y=[z;y;z];
rr=2*pi/round(fs*r);
b=round((v/2)*(1-cos(rr.*n)));
y=y(n+md)+y(n+md-b);
m=m/max(abs(y));
y=m*y;
%filtro para que no clipee
[ZL,PL,KL]=butter(1,3000/(fs/2),'low');
[BL,AL]=zp2tf(ZL,PL,KL);
y=filter(BL,AL,y);
normout=norm(y);
y=y*norms/normout;

end
